

using System.Linq;
using Abp.Authorization;
using Abp.Configuration.Startup;
using Abp.Localization;
using Abp.MultiTenancy;
using JYJ.AiYard.Authorization;

namespace JYJ.AiYard.StationManagement.TbYardParamsSets.Authorization
{
    /// <summary>
    /// 权限配置都在这里。
    /// 给权限默认设置服务
    /// See <see cref="TbYardParamsSetPermissions" /> for all permission names. TbYardParamsSet
    ///</summary>
    public class TbYardParamsSetAuthorizationProvider : AuthorizationProvider
    {
        private readonly bool _isMultiTenancyEnabled;

		public TbYardParamsSetAuthorizationProvider()
		{

		}

        public TbYardParamsSetAuthorizationProvider(bool isMultiTenancyEnabled)
        {
            _isMultiTenancyEnabled = isMultiTenancyEnabled;
        }

        public TbYardParamsSetAuthorizationProvider(IMultiTenancyConfig multiTenancyConfig)
        {
            _isMultiTenancyEnabled = multiTenancyConfig.IsEnabled;
        }

		public override void SetPermissions(IPermissionDefinitionContext context)
		{
			// 在这里配置了TbYardParamsSet 的权限。
			var pages = context.GetPermissionOrNull(AppLtmPermissions.Pages) ?? context.CreatePermission(AppLtmPermissions.Pages, L("Pages"));

			var administration = pages.Children.FirstOrDefault(p => p.Name == AppPermissions.Pages_YardManage) ?? pages.CreateChildPermission(AppPermissions.Pages_YardManage, L("Yard_Management"));

			var entityPermission = administration.CreateChildPermission(TbYardParamsSetPermissions.Node , L("YardParamsSet"));
			entityPermission.CreateChildPermission(TbYardParamsSetPermissions.Query, L("QueryTbYardParamsSet"));
			entityPermission.CreateChildPermission(TbYardParamsSetPermissions.Create, L("CreateTbYardParamsSet"));
			entityPermission.CreateChildPermission(TbYardParamsSetPermissions.Edit, L("EditTbYardParamsSet"));
			entityPermission.CreateChildPermission(TbYardParamsSetPermissions.Delete, L("DeleteTbYardParamsSet"));
            entityPermission.CreateChildPermission(TbYardParamsSetPermissions.BatchDelete, L("BatchDeleteTbYardParamsSet"));
            entityPermission.CreateChildPermission(TbYardParamsSetPermissions.ParamsSet, L("TbStationParam"));
            entityPermission.CreateChildPermission(TbYardParamsSetPermissions.ParamsSetEdit, L("EditTbStationParam"));
            
            //entityPermission.CreateChildPermission(TbYardParamsSetPermissions.ExportExcel, L("ExportExcelTbYardParamsSet"));


        }

		private static ILocalizableString L(string name)
		{
			return new LocalizableString(name, AppConsts.LocalizationSourceName);
		}
    }
}